package com.iuie.ns.system.vo.role;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.iuie.ns.system.vo.authority.SysAuthorityVO;
import com.iuie.ns.system.vo.resource.SysResourceVO;
import com.iuie.ns.system.vo.user.SysUserVO;

/**
 * 角色
 * @author lj
 * @createTime 2017年1月1日 下午6:24:54
 */
@Table(name="SYS_ROLE")
@Entity
public class SysRoleVO {

	@Column(name = "ROLE_ID",length=32)
	@Id
	private String roleId; // 角色ID

	@Column(name = "ROLE_CODE", unique = true, nullable = false)
	private String roleCode; // 角色编码

	@Column(name = "ROLE_NAME")
	private String roleName; // 角色名称
	
	private Character roleState; // 角色状态

	@Column(name = "ROLE_DESC")
	private String roleDesc; // 角色描述

	@JoinTable(name = "SYS_ROLE_AUTHORITY", 
			joinColumns = { @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID") }, 
			inverseJoinColumns = { @JoinColumn(name = "AUTHORITY_ID", referencedColumnName = "AUTHORITY_ID") })
	@ManyToMany(fetch=FetchType.EAGER,cascade={CascadeType.REMOVE}) // fetch 属性设置是否懒加载集合属性，EAGER表示立即加载，LAZY表示懒加载
	private Set<SysAuthorityVO> authoritys = new HashSet<SysAuthorityVO>(); // 角色
	
	@JoinTable(name="SYS_USER_ROLE",
			joinColumns = { @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID") }, 
			inverseJoinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "USER_ID") })
	@ManyToMany()
	private Set<SysUserVO> users = new LinkedHashSet<>();
	
	@JoinTable(name="SYS_ROLE_RESOURCE",
            joinColumns = { @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID") }, 
            inverseJoinColumns = { @JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID") })
    @ManyToMany()
	private Set<SysResourceVO> resources = new LinkedHashSet<>();
	
	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleDesc() {
		return roleDesc;
	}

	public void setRoleDesc(String roleDesc) {
		this.roleDesc = roleDesc;
	}

	public Set<SysAuthorityVO> getAuthoritys() {
		return authoritys;
	}

	public void setAuthoritys(Set<SysAuthorityVO> authoritys) {
		this.authoritys = authoritys;
	}

	public Set<SysUserVO> getUsers() {
		return users;
	}

	public void setUsers(Set<SysUserVO> users) {
		this.users = users;
	}
    public Set<SysResourceVO> getResources() {
        return resources;
    }
    public void setResources(Set<SysResourceVO> resources) {
        this.resources = resources;
    }
    public Character getRoleState() {
        return roleState;
    }
    public void setRoleState(Character roleState) {
        this.roleState = roleState;
    }

    @Override
    public String toString() {
        return "SysRoleVO [roleId=" + roleId + ", roleCode=" + roleCode + ", roleName=" + roleName + ", roleState=" + roleState + ", roleDesc=" + roleDesc + ", authoritys="
                + authoritys + ", users=" + users + ", resources=" + resources + "]";
    }

	
}
